import Vue from 'vue';
import Router from 'vue-router';
import adminRoutes from './modules/admin';
import poorRoutes from './modules/poor';

Vue.use(Router)

export const createRouter = (isAdmin) => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: isAdmin ? adminRoutes : poorRoutes
})

const router = createRouter(false)

// 通过权限信息重置路由routes
export function resetRouter(isAdmin) {
  const newRouter = createRouter(isAdmin)
  router.matcher = newRouter.matcher // reset router
}

export default router
